package com.todoclipse.view;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;

import com.todoclipse.api.ProjectItem;
import com.todoclipse.common.DaoException;
import com.todoclipse.dao.DaoFactory;
import com.todoclipse.dao.ItemDao;
import com.todoclipse.dao.UserDao;

public class MainView extends ViewPart {
	
	public Collection<ProjectItem> listProjects() {
		DaoFactory daoFactory = DaoFactory.getInstance();
		UserDao manager = daoFactory.getUserDao();
		try {
//			manager.userRegister("todoclipse@o2.pl", "todoclipse", "Test",TimeZone.getDefault());
			String token = manager.userLogin("todoclipse@o2.pl", "todoclipse");
			System.out.println(token);
			ItemDao itemDao = daoFactory.getItemDao(token);
			List<ProjectItem> allProjects = itemDao.getAllProjects();
			return allProjects;
		} catch (DaoException e) {
			e.printStackTrace();
			return new ArrayList<ProjectItem>();
		}
	}

	@Override
	public void createPartControl(Composite parent) {
		Text text = new Text(parent, SWT.BORDER);
		text.setText(listProjects().toString());
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

}
